home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Source / Strip.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  1.1 KB  |  71 lines

  1. #include <exec/types.h>
  2.  
  3. #include <clib/extras/string_protos.h>
  4.  
  5. /****** extras.lib/str_Strip ******************************************
  6. *
  7. *   NAME
  8. *       str_Strip - Remove leading and trailing white spaces.
  9. *
  10. *   SYNOPSIS
  11. *       str_Strip(Str)       
  12. *
  13. *       void Strip(STRPTR);
  14. *
  15. *   FUNCTION
  16. *       This function removes leading and trailing whites-paces
  17. *       from a string.  White-spaces are determined by the 
  18. *       IsWhiteSpace() function.
  19. *
  20. *   INPUTS
  21. *       Str - a null terminated string pointer.
  22. *
  23. *   RESULT
  24. *       none.
  25. *
  26. *   EXAMPLE
  27. *
  28. *   NOTES
  29. *       Modifies existing string memory.
  30. *
  31. *   BUGS
  32. *       Will not work on NNStr used by other some functions in 
  33. *       the extras.lib.
  34. *
  35. *   SEE ALSO
  36. *       IsWhiteSpace().
  37. *
  38. ******************************************************************************
  39. *
  40. */
  41.  
  42.  
  43. void str_Strip(STRPTR Str)
  44. {
  45.   STRPTR  s1,s2;
  46.   
  47.   s1=s2=Str;
  48.   
  49.   while(IsWhiteSpace(*s2))
  50.     s2++;
  51.   
  52.   while(*s2)
  53.   {
  54.     *s1=*s2;
  55.     s1++;
  56.     s2++;
  57.   }
  58.   
  59.   *s1=0;
  60.   
  61.   while(s1>Str)
  62.   {
  63.     s1--;
  64.     if(IsWhiteSpace(*s1))
  65.       *s1=0;
  66.     else
  67.       return;
  68.   }
  69. }
  70.  
  71.